<template>
	<view class="container">

		<view class="row">
			<view class="title">
				公司名称：
			</view>
			<view class="input-box">
				<input type="text" :value="company" @input="importCompany" @blur="importCompany" />
			</view>
		</view>
		<view class="row">
			<view class="title">
				联系人：
			</view>
			<view class="input-box">
				<input type="text" :value="name" @input="importName" @blur="importName" />
			</view>
		</view>
		<view class="row">
			<view class="title">
				手机号：
			</view>
			<view class="input-box">
				<input type="text" :value="tel" @input="importTel" @blur="importTel" />
			</view>
		</view>
		<view class="row">
			<view class="title">
				验证码：
			</view>
			<view class="input-box">
				<input type="text" :value="code" @input="importCode" @blur="importCode" />
			</view>
			<view class="get-code" @click="getCode">
				{{codeText}}
			</view>
		</view>
		<view class="btn" @click="open">
			绑定
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup-wrap">
				<view class="close-icon" @click="close()">
					<image src="../../static/img/gb.png" mode=""></image>
				</view>
				<view class="big-title">
					绑定通知
				</view>
				<view class="sm-title">是否确认绑定该企业信息，如成功绑定后则无法修改。</view>
				<view class="btn-box row">
					<view class="confirm" @click="bind()">
						确定
					</view>
					<view class="cancel" @click="close()">
						取消
					</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="result" type="center">
			<view class="popup-wrap">
				<view class="close-icon" @click="close2()">
					<image src="../../static/img/gb.png" mode=""></image>
				</view>
				<view class="big-title">
					绑定通知
				</view>
				<view class="sm-title">{{result}}</view>
				<view class="btn-box row">
					<view class="confirm" @click="close2()">
						确定
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import comm from '../../static/data/commFunc.js'
	import cfg from '../../static/data/config.js'
	var r = cfg.router;
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniNumberBox from "@/components/uni-number-box/uni-number-box.vue"
	export default {
		data() {
			return {
				name: "",
				company: "",
				tel: "",
				code: "",
				result: "",
				codeText: "获取",
				snsMsgWait: 60, //时间秒
			};
		},
		methods: {

			bind() {
				let data = {
					mobile: this.tel,
					company: this.company,
					contact: this.name,
					captcha: this.code
				}
				comm.request("POST", "/app/member/bindingCompay", data, (res, data) => {
					console.log("绑定企业", res)
					if (res.data.ret_code == 200) {
						this.result = "恭喜你，已成功绑定企业！"
						this.$refs.result.open()
						this.$refs.popup.close()
					} else {
						this.result = res.data.ret_msg
						// this.result = "无法查询到该企业，请联系客服！"
						this.$refs.result.open()
						this.$refs.popup.close()
						// comm.showToast(res.data.ret_msg, "none")
					}
				})
			},
			getCode() {
				// 60秒后重新获取验证码
				if(this.tel == ''){
					comm.showToast("请输入手机号码","none")
					return
				}else if(!comm.isMobile(this.tel)){
					comm.showToast("请输入正确的手机号码","none")
					return
				}
				if (this.codeText == '获取') {
					var inter = setInterval(function() {
						this.codeText = "重新发送(" + this.snsMsgWait + ")"
						this.snsMsgWait = this.snsMsgWait - 1
						this.snsDisabled = true
						if (this.snsMsgWait < 0) {
							clearInterval(inter)
							this.codeText = "获取",
								this.snsMsgWait = 60								
						}
					}.bind(this), 1000);
					let data = {mobile:this.tel}
					comm.request("POST", "/public/getCaptcha", data, (res, data) => {
						console.log("获取验证码", res)
						if (res.data.ret_code == 200) {
								comm.showToast("已发送")
						} else {
							comm.showToast(res.data.ret_msg, "none")
							this.codeText = '获取'
						}
					})
				}
			},
			importCompany(e) {
				this.company = e.detail.value
			},
			importName(e) {
				this.name = e.detail.value
			},
			importTel(e) {
				this.tel = e.detail.value
			},
			importCode(e){
				this.code =  e.detail.value
			},
			open() {
				if (this.company == '') {
					comm.showToast("请输入公司名称", "none")
					return
				} else if (this.name == '') {
					comm.showToast("请输入联系人", "none")
					return
				} else if (this.tel == '') {
					comm.showToast("请输入手机号", "none")
					return
				} else if (!comm.isMobile(this.tel)) {
					comm.showToast("请输入正确的手机号", "none")
					return
				} else if (this.code == '') {
					comm.showToast("请输入验证码", "none")
					return
				}
				this.$refs.popup.open()
			},
			close() {
				this.$refs.popup.close()

			},
			close2() {
				this.$refs.result.close()
			}
		}
	}
</script>

<style lang="less">
	.container {
		padding: 30rpx;
	}

	.title {
		width: 180rpx;
	}

	.row {
		justify-content: space-between;
	}

	.upload-box {
		flex: 1;
		margin-bottom: 20rpx;

		image {
			width: 242rpx;
			height: 168rpx;

		}

		.bg {
			background: #E5E5E5;
		}
	}

	.input-box {
		flex: 1;
		margin: 20rpx 0;
		border: 1rpx solid #E5E5E5;
		border-radius: 8rpx;
		padding: 10rpx 20rpx;

		input {
			width: 100%;
		}
	}

	.get-code {
		background: rgba(217, 48, 17, 1);
		border-radius: 30rpx;
		padding: 10rpx 20rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		margin-left: 30rpx;
	}

	.btn {
		width: 100%;
		text-align: center;
		padding: 25rpx 0;
		font-size: 28rpx;
		color: #FFFFFF;
		background: rgba(219, 48, 18, 1);
		border-radius: 40rpx;
		margin-top: 30rpx;
	}

	.popup-wrap {
		width: 690rpx;
		padding: 50rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		border-radius: 30rpx;
		position: relative;
		margin: 0 auto;

		.close-icon {
			position: absolute;
			top: 30rpx;
			right: 30rpx;

			image {
				width: 36rpx;
				height: 36rpx;
			}
		}

		.big-title {
			text-align: center;
			font-size: 34rpx;
			font-weight: bold;
			color: rgba(51, 51, 51, 1);
			margin-bottom: 38rpx;
		}

		.sm-title {
			font-size: 28rpx;
			color: rgba(51, 51, 51, 1);
			text-align: center;
			margin: 50rpx 0;
		}

		.btn-box {
			justify-content: space-around;

			.confirm {
				width: 263rpx;
				height: 72rpx;
				line-height: 72rpx;
				background: rgba(217, 48, 17, 1);
				border: 1px solid rgba(219, 48, 18, 1);
				border-radius: 36rpx;
				text-align: center;
				font-size: 28rpx;
				color: #FFFFFF;
			}

			.cancel {
				width: 263rpx;
				height: 72rpx;
				line-height: 72rpx;
				border-radius: 36rpx;
				text-align: center;
				font-size: 28rpx;
				color: rgba(217, 48, 17, 1);
				border: 1px solid rgba(219, 48, 18, 1);
			}
		}
	}
</style>
